package org.example.doctorapi.server.Imp;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.micrometer.common.util.StringUtils;
import org.example.doctorapi.data.SysDictData;
import org.example.doctorapi.mapper.SysDictDataMapper;
import org.example.doctorapi.server.SysDictDataServer;
import org.example.doctorapi.util.IdGeneration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;
@Service
public class SysDictDataServerImp implements SysDictDataServer {
    @Autowired
    private SysDictDataMapper sysDictDataMapper;
    private static final IdGeneration<SysDictData> idGeneration = new IdGeneration<>();
    @Override
    public Page<SysDictData> checkDictDataAll(SysDictData sysDictData) {
        return idGeneration.GetRecords(sysDictData,null,sysDictDataMapper);
    }

    @Override
    public Page<SysDictData> checkDictDataSome(SysDictData sysDictData) {
        QueryWrapper<SysDictData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(sysDictData.getDictType()),
                SysDictData.DICT_TYPE,sysDictData.getDictType());
        queryWrapper.like(StringUtils.isNotBlank(sysDictData.getDictLabel()),
                SysDictData.DICT_LABEL,sysDictData.getDictLabel());
        queryWrapper.eq(StringUtils.isNotBlank(sysDictData.getStatus()),
                SysDictData.STATUS,sysDictData.getStatus());
        return idGeneration.GetRecords(sysDictData,queryWrapper,sysDictDataMapper);
    }

    @Override
    public Page<SysDictData> getOneByDictId(Integer id){
        QueryWrapper<SysDictData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SysDictData.DICT_CODE,id);
        return idGeneration.GetRecords(new SysDictData(),queryWrapper,sysDictDataMapper);
    }

    @Override
    public void insertOne(SysDictData sysDictData){
        sysDictData.setCreateTime(DateUtil.date());
        sysDictDataMapper.insert(sysDictData);
    }
    @Override
    public void updateOne(SysDictData sysDictData){
        sysDictData.setUpdateTime(DateUtil.date());
        sysDictDataMapper.updateById(sysDictData);
    }

    @Override
    public void deleteAll(List<Integer> ids){
        sysDictDataMapper.deleteBatchIds(ids);
    }

    @Override
    public void deleteById(Integer id) {
        sysDictDataMapper.deleteById(id);
    }
}
